#coding: utf-8
"""
Created on Mon Aug 25 13:57:11 2014

@author: loseair123


#函数

def fun():
    print 'this is a function!'

fun()

#函数重载
def buyIcegream(num=1,favour='巧克力'):
    print '你确认购买',num,'个,',favour,'口味的巧克力吗？'

buyIcegream()

buyIcegream(2)

buyIcegream(3,'奶油味')

buyIcegream(favour='melo')


#函数局部变量

def changeX(x):
    print 'x passed is',x
    print 'change x value to 100'
    x=100

x=20
changeX(x)
print 'after change: X=',x

#none 和 pass

def getMax(x,y):
    if x>y:
        return x
    elif x<y:
        return y
    elif x==y:
        return None


print(getMax(5,15))
print(getMax(15,15))
print(getMax(5,2))

#全局变量
y='original'
def changetoGlobal():
    global y
    y='changed'

print y
changetoGlobal()
print 'after changed',y


#冗余参数
p1=[10,9]
p2={'x':'eko','y':24}
p3=range(5)
def fun(x,y):
    print x,y

fun(*p1)
fun(**p2)

def fun2(x,y,*arg):
    print x
    print y
    print arg

fun2(*p3) 

#lambda匿名函数

g=lambda x,y:x+y
print g(*p1)
print g

#reduce函数
num=reduce(lambda x,y:x*y,range(1,11))
print num

#python中的switch 一般用字典来实现
#from __future__ import division

def plus(x,y):
    print x+y

def subtract(x,y):
    print x-y

def multiply(x,y):
    print x*y
    
def divide(x,y):
    print x/y
    
calcu={'+':plus,'-':subtract,'*':multiply,'/':divide}

def calculator(x,o,y):
    calcu.get(o)(x,y)
    

calculator(7,'+',8)
calculator(7,'-',8)
calculator(7,'*',8)

#常用系统内置函数

print abs(-25.1)
print max([15,48,78])
print min([15,-1,25])
print divmod(8,3)
print pow(2,4)
print pow(2,5,3)
print cmp('qwe','wqeq')
print callable(plus)
print callable('minus')

#与类型相关的内置函数
str1='eko,hello,world!'
print str1.capitalize()
print str1.replace('l','1',2)
print str1.split(',',1)

#filter，zip,map函数的使用方法
def f(x):
    if x>5:
        return True

l=xrange(15)

print filter(f,l)

l1=['eko','daisy','ye']
l2=[22,22,23]
l3=['123','159','186']
l=['banana','apple']
l4=[1,2,3]
l5=[4,5,6]

def f(x,y):
    return x*y
print zip(l1,l2,l3)
print zip(l1,l2,l3,l)
print map(None,l1,l2,l3)
print map(None,l1,l2,l3,l)
print map(f,l4,l5)
print map(f,l1,l2)

#模块的导入和包的定义
#import test.cal
import test.cal as C
print C.add(2,3)

"""